﻿using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Threading;
using System.Windows.Forms;

namespace demo02_填充
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            SolidBrush brush = new SolidBrush(Color.Red);
            g.FillEllipse(brush, 120, 100, 150, 150);
            brush.Dispose();
            g.Dispose();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.Clear(BackColor);
            g.Dispose();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Point p1 = new Point(140, 120);
            Point p2 = new Point(250, 240);
            Brush brush = new LinearGradientBrush(p1, p2, Color.Red, Color.Yellow);
            g.FillEllipse(brush, 120, 100, 150, 150);
            brush.Dispose();
            g.Dispose();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Brush brush;
            foreach (HatchStyle x in Enum.GetValues(typeof(HatchStyle)))    //注意Enum必须为大写
            {
                g.Clear(BackColor);
                brush = new HatchBrush(x, Color.Red, Color.LimeGreen);
                g.FillEllipse(brush, 120, 100, 150, 150);
                Thread.Sleep(500);
            }
            g.Dispose();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Brush brush = new TextureBrush(Image.FromFile("加油.png"));
            g.FillEllipse(brush, 120, 100, 150, 150);
            Thread.Sleep(2000);
            g.Clear(BackColor);
            brush = new TextureBrush(Image.FromFile("花朵.png"));
            g.FillRectangle(brush, 120, 100, 150, 150);
            brush.Dispose();
            g.Dispose();
        }
    }
}
